const Controller = require("../core/base_controller");

/**
 * @Controller 新闻管理
 */
class NewsController extends Controller {
  async list() {
    const dataList = [
      { id: 1, title: "this is news 1", url: "/news/1" },
      { id: 2, title: "this is news 2", url: "/news/2" },
    ];
    this.success(dataList);
  }

  async searchByrouter(ctx) {
    //   params参数
    const params = ctx.params;
    this.success(params);
  }

  /**
   * @summary 搜索query
   * @router get /searchquery
   * @request query string str 随机字符串
   * @response 200 response
   */
  async searchByquery(ctx) {
    //   query参数
    const query = ctx.query;
    // ||为了重复输入
    const id = query.id || "";
    // query重名参数
    const queries = ctx.queries;
    this.success(query);
  }

  /**
   * @summary 搜索body
   * @router post /searchbody
   * @request body string str 随机字符串
   * @response 200 response
   */
  async searchBybody(ctx) {
    //   query参数
    const body = ctx.request.body;
    this.success(body);
  }

  async searchByheader(ctx) {
    //   header参数
    const header = ctx.header;
    const token = ctx.get("token");
    console.log(token);

    const ips = ctx.ips;
    const ip = ctx.ip;
    console.log(ips.length != 0 ? ips : ip);

    this.success(token);
  }

  async none() {
    this.notFound("老王你的404");
  }
}
module.exports = NewsController;
